package com.peanut.baby.mvp.mydata;

import android.app.Activity;

import com.peanut.baby.InitManager;
import com.peanut.baby.http.BaseObserver;
import com.peanut.baby.http.BaseScheduler;
import com.peanut.baby.http.RetrofitClient;
import com.peanut.baby.model.Record;

import java.util.List;

import cn.nekocode.rxlifecycle.RxLifecycle;
import io.reactivex.Observable;

/**
 * Created by anonymouslystudio on 2017/8/28.
 */

public class TiaoliListPresenter implements RecordListContract.Presenter{
    RecordListContract.View view;
    Activity activity;
    public TiaoliListPresenter(RecordListContract.View view,Activity activity) {
        this.view = view;
        this.activity = activity;
    }

    @Override
    public void getRecordList(int pageNo, int pageSize) {
        Observable obs = RetrofitClient.getInstance().getTiaolliList(pageNo,pageSize, InitManager.getInstance().getUserId(),
                InitManager.getInstance().getUser().userToken);
        obs.compose(BaseScheduler.<List<Record>>compose())
                .compose(RxLifecycle.bind(activity).withObservable())
                .subscribe(new BaseObserver<List<Record>>() {
            @Override
            protected void onHandleSuccess(List<Record> o) {
                view.onListGet(o);
            }

            @Override
            protected void onHandleError(String code,String msg) {
                view.onGetListFailed(msg);
            }
        });
    }
}
